<?php
class Cms_BannerController extends Zend_Controller_Action {
    private $_languages = array();
    public function init() {
    	$this->_languages = Utils_Global::getSupportLanguages();
    }
    
	public function homePageBigBannerAction() {
	     $pos = $this->_request->getParam('position');
	     $limit = $this->_request->getParam('limit');
	     if(!$limit) {
	         $limit = 4;
	     }
	     if($pos == -1) {
	         if(Utils_Global::getCurrentLanguage() == 'en') {
	             $pos = 6;
	         } else {
	             $pos = 1;
	         }
	     }
	     $bannerModel = Cms_Model_Banner::factory();
	     $banner = $bannerModel->getBanner($pos, $limit);
	     $this->view->staticUrl = Utils_Global::get('staticUrl') . '/banner/';
	     $this->view->banners = $banner;
	}
	
	public function galleryHomePageAction() {
	    $pos = $this->_request->getParam('position');
	    $limit = $this->_request->getParam('limit');
	    $lang = Utils_Global::$params['lang'];
	    $bannerModel = Cms_Model_Banner::factory();
	    $banner = $bannerModel->getAlbums(20, 0);
	    $this->view->staticUrl = Utils_Global::get('staticUrl') . '/banner/';
	    $this->view->banners = $banner;
	    $this->view->lang = $lang;
	}
	
	public function partnerHomePageAction() {
	    $pos = $this->_request->getParam('position');
	    $limit = $this->_request->getParam('limit');
	    $lang = Utils_Global::$params['lang'];
	    if(!$limit) {
	        $limit = 3;
	    }
	     
	    $bannerModel = Cms_Model_Banner::factory();
	    $banner = $bannerModel->getBanner($pos, $limit);
	    $this->view->staticUrl = Utils_Global::get('staticUrl') . '/banner/';
	    $this->view->banners = $banner;
	    $this->view->lang = $lang;
	}
	
	public function customerHomePageAction() {
	    $pos = $this->_request->getParam('position');
	    $limit = $this->_request->getParam('limit');
	    $lang = Utils_Global::$params['lang'];
	    if(!$limit) {
	    	$limit = 20;
	    }
	    
	    $bannerModel = Cms_Model_Banner::factory();
	    $banner = $bannerModel->getBanner($pos, $limit);
	    $this->view->staticUrl = Utils_Global::get('staticUrl') . '/banner/';
	    $this->view->banners = $banner;
	    $this->view->lang = $lang;
	}
	
	public function customersAction() {
	    $pos = $this->_request->getParam('pos');
	    $page = intval(Utils_Global::$params['page']);
	    $limit = intval(Utils_Global::$params['limit']);
	    $lang = Utils_Global::$params['lang'];
	    if(!in_array($lang, $this->_languages)) {
	    	$lang = Utils_Global::getCurrentLanguage();
	    }
	    if($page < 1) {
	    	$page = 1;
	    }
	    if($limit <= 0){
	    	$limit = 16;
	    }
	    
	    $model = Cms_Model_Banner::factory();
	    $banners = $model->getBanner($pos, $limit, ($page - 1) * $limit);
	    $breadcrumbData = array(
	    		array('url' => $this->view->serverUrl(),
	    				'displayName' => $this->view->translate('home', $lang),
	    				'title' => $this->view->translate('home', $lang),
	    		),
	    		array(
	    				'url' => 'javascript:void(0)',
	    				'displayName' => $this->view->translate('page_customer', $lang),
	    				'title' => $this->view->translate('page_customer', $lang),
	    		),
	    );
	     
	    $this->view->breadcrumb = $breadcrumbData;
	    $this->view->lang = $lang;
	    $this->view->banners = $banners;
	    $this->view->page = $page;
	    $this->view->totalItem = $model->getBannerCount($pos);
	    $this->view->numRowPerPage = $limit;
	    $this->view->staticUrl = Utils_Global::get('staticUrl') . '/banner/';
	    $this->view->position = $pos;
	    Utils_Global::$params['customerclzz'] = 'current';
	    $this->view->metadata = $this->view->metadata('home', array('title_label' => $this->view->translate('seo_page_customer_title', $lang),
	                                                                'description_label' => $this->view->translate('seo_page_customer_description', $lang),
	    ),
	    		$this->view->serverUrl() . $this->view->url(array()));
	    if(Utils_Global::get('isAjax')) {
	    	$this->_helper->layout()->disableLayout();
	    	$this->render('customers-content');
	    } else {
	        $this->view->content = $this->view->render('banner/customers-content.phtml');
	    }
	}
	
	public function galleriesAction() {
	    $page = intval(Utils_Global::$params['page']);
	    $limit = intval(Utils_Global::$params['limit']);
	    $lang = Utils_Global::$params['lang'];
	    if(!in_array($lang, $this->_languages)) {
	    	$lang = Utils_Global::getCurrentLanguage();
	    }
	    if($page < 1) {
	    	$page = 1;
	    }
	    if($limit <= 0){
	    	$limit = 10;
	    }
	    
	    $model = Cms_Model_Banner::factory();
	    $banners = $model->getAlbums($limit, ($page - 1) * $limit);
	    $breadcrumbData = array(
	    		array('url' => $this->view->serverUrl(),
	    				'displayName' => $this->view->translate('home', $lang),
	    				'title' => $this->view->translate('home', $lang),
	    		),
	    		array(
	    				'url' => 'javascript:void(0)',
	    				'displayName' => $this->view->translate('page_galleries', $lang),
	    				'title' => $this->view->translate('page_galleries', $lang),
	    		),
	    );
	    
	    $this->view->breadcrumb = $breadcrumbData;
	    $this->view->lang = $lang;
	    $this->view->banners = $banners;
	    $this->view->page = $page;
	    $this->view->totalItem = $model->getAlbumCount();
	    $this->view->numRowPerPage = $limit;
	    $this->view->staticUrl = Utils_Global::get('staticUrl') . '/banner/';
	    $this->view->position = $pos;
	    $this->view->metadata = $this->view->metadata('home', array('title_label' => $this->view->translate('seo_page_galleries_title', $lang),
	                                                                   'description_label' => $this->view->translate('seo_page_galleries_description', $lang),
	    ),
	    		$this->view->serverUrl() . $this->view->url(array()));
	    Utils_Global::$params['galleryclzz'] = 'current';
	    if(Utils_Global::get('isAjax')) {
	    	$this->_helper->layout()->disableLayout();
	    	$this->render('galleries-content');
	    } else {
	    	$this->view->content = $this->view->render('banner/galleries-content.phtml');
	    }
	}
}
